/**
 * 更新npm
 */

var cp = require("child_process"),
    tool = require("./tool");

module.exports = function (fn) {
    tool.log("Download npm install dependencies...");
    tool.startWaitLog();

    cp.exec("npm install --prefix ./.build/", function (err) {
        tool.stopWaitLog();
        if (err) {
            console.log(err);
            console.error("\nError: Npm install failed!");
        } else {
            require("shelljs/global");
            require("colors");

            if (exec("git clone http://git.oschina.net/fingerplus/build.json .build/build.json").code != 0) {
                console.log("git clone fatal!".red);
            } else {
                fn();
            }

        }
    }).stdout.on("data", function (data) {
            console.log(data);
        });
}